package cn.aitrox.ry.service.anno.dao.impl;

import cn.aitrox.ry.common.dao.MapperSqlCallback;
import cn.aitrox.ry.common.dao.impl.BaseDaoImpl;
import cn.aitrox.ry.constant.CommonConstant;
import cn.aitrox.ry.service.anno.dao.AnnoLesionResultDao;
import cn.aitrox.ry.service.anno.entity.AnnoLesionResultEntity;
import cn.aitrox.ry.service.anno.mapper.AnnoLesionResultMapper;
import cn.aitrox.ry.service.anno.po.anno.lesion.result.ArIdAlrCountPo;
import cn.aitrox.ry.util.ArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class AnnoLesionResultDaoImpl extends BaseDaoImpl<AnnoLesionResultEntity> implements AnnoLesionResultDao {

    @Autowired
    private AnnoLesionResultMapper mapper;

    @Override
    public List<ArIdAlrCountPo> findCountGroupByArId(List<Integer> arIds) {
        if (ArrayUtil.isEmpty(arIds)) {
            return new ArrayList<>();
        }
        return mapper.findCountGroupByArId(arIds);
    }

    @Override
    public List<AnnoLesionResultEntity> findByArId(Integer arId) {
        if (null == arId) {
            return new ArrayList<>();
        }
        AnnoLesionResultEntity cond = new AnnoLesionResultEntity();
        cond.setArId(arId);
        return super.findByCondition(cond, null);
    }

    @Override
    public List<AnnoLesionResultEntity> findByArIds(List<Integer> arIdList) {
        return mapper.findByArIds(arIdList);
    }

    @Override
    public void clearMaskFilePath(List<Integer> ids) {
        if (ArrayUtil.isEmpty(ids)) {
            return;
        }
        AnnoLesionResultEntity update = new AnnoLesionResultEntity();
        update.setMaskFilePath(CommonConstant.EMPTY);
        super.updateByIdsSelective(update, ids.toArray());
    }

    @Override
    public void updateMaskPath(Integer id, String maskFilePath) {
        if (null == id) {
            return;
        }
        AnnoLesionResultEntity update = new AnnoLesionResultEntity();
        update.setId(id);
        update.setMaskFilePath(maskFilePath);
        super.updateByIdSelective(update);
    }

    @Override
    public void batchSave(List<AnnoLesionResultEntity> list) {
        super.batchInsert(list, 1000, new MapperSqlCallback<AnnoLesionResultEntity>() {
            @Override
            public void batchInsert(List<AnnoLesionResultEntity> objList) {
                mapper.batchInsert(objList);
            }
        });
    }

    @Override
    public List<Integer> findIdByArIdGroupId(Integer arId, Integer groupId) {
        return mapper.findIdByArIdGroupId(arId, groupId);
    }
}
